home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-03 / qbasicpg.zip / TERMINAL.BAS < prev    next >
BASIC Source File  |  1987-09-22  |  2KB  |  75 lines

  1. DEFINT A-Z
  2.  
  3. DECLARE SUB Filter (InString$)
  4.  
  5. COLOR 7, 1                      ' Set screen color.
  6. CLS
  7.  
  8. Quit$ = CHR$(0) + CHR$(16)      ' Value returned by INKEY$
  9.                                 ' when ALT+q is pressed.
  10.  
  11. ' Set up prompt on bottom line of screen and turn cursor on:
  12. LOCATE 24, 1, 1
  13. PRINT STRING$(80, "_");
  14. LOCATE 25, 1
  15. PRINT TAB(30); "Press ALT+q to quit";
  16.  
  17. VIEW PRINT 1 TO 23              ' Print between lines 1 & 23.
  18.  
  19. ' Open communications (1200 baud, no parity, 8-bit data,
  20. ' 1 stop bit, 256-byte input buffer):
  21. OPEN "COM1:1200,N,8,1" FOR RANDOM AS #1 LEN = 256
  22.  
  23. DO                              ' Main communications loop.
  24.  
  25.    KeyInput$ = INKEY$           ' Check the keyboard.
  26.  
  27.    IF KeyInput$ = Quit$ THEN    ' Exit the loop if the user
  28.       EXIT DO                   ' pressed ALT+q.
  29.  
  30.    ELSEIF KeyInput$ <> "" THEN  ' Otherwise, if the user has
  31.       PRINT #1, KeyInput$;      ' pressed a key, send the
  32.    END IF                       ' character typed to the modem.
  33.  
  34.    ' Check the modem. If characters are waiting (EOF(1) is
  35.    ' true), get them and print them to the screen:
  36.    IF NOT EOF(1) THEN
  37.  
  38.       ' LOC(1) gives the number of characters waiting:
  39.       ModemInput$ = INPUT$(LOC(1), #1)
  40.  
  41.       Filter ModemInput$        ' Filter out line feeds and
  42.       PRINT ModemInput$;        ' backspaces, then print.
  43.    END IF
  44. LOOP
  45.  
  46. CLOSE                           ' End communications.
  47. CLS
  48. END
  49. '
  50. ' ========================= FILTER ==========================
  51. '     Filters characters in an input string.
  52. ' ============================================================
  53. '
  54. SUB Filter (InString$) STATIC
  55.  
  56.    ' Look for backspace characters and recode them to
  57.    ' CHR$(29) (the LEFT cursor key):
  58.    DO
  59.       BackSpace = INSTR(Instring$, CHR$(8))
  60.       IF BackSpace THEN
  61.          MID$(InString$, BackSpace) = CHR$(29)
  62.       END IF
  63.    LOOP WHILE BackSpace
  64.  
  65.    ' Look for line-feed characters and remove any found:
  66.    DO
  67.       LineFeed = INSTR(Instring$, CHR$(10))
  68.       IF LineFeed THEN
  69.          InString$ = LEFT$(InString$, LineFeed - 1) + _
  70.                       MID$(InString$, LineFeed + 1)
  71.       END IF
  72.    LOOP WHILE LineFeed
  73.  
  74. END SUB
  75.